package com.ruoyi.park.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.park.domain.WyUser;
import com.ruoyi.park.service.IWyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 物业人员Controller
 *
 * @author cjie
 * @date 2021-07-22
 */
@Api(tags = " 物业人员")
@RestController
@RequestMapping("/wyUser")
public class WyUserController extends BaseController {
    @Autowired
    private IWyUserService wyUserService;

    /**
     * 查询物业人员列表
     */
    @ApiOperation(value="查询物业人员列表", notes="查询物业人员列表")
    @PreAuthorize(hasPermi = "park:wyUser:list")
    @GetMapping("/list")
    public TableDataInfo list(WyUser wyUser) {
        startPage();
        List<WyUser> list = wyUserService.selectWyUserList(wyUser);
        return getDataTable(list);
    }

    /**
     * 导出物业人员列表
     */
    @ApiOperation(value="导出物业人员列表", notes="导出物业人员列表")
    @PreAuthorize(hasPermi = "park:wyUser:export")
    @Log(title = "物业人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyUser wyUser) throws IOException {
        List<WyUser> list = wyUserService.selectWyUserList(wyUser);
        ExcelUtil<WyUser> util = new ExcelUtil<WyUser>(WyUser.class);
        util.exportExcel(response, list, "物业人员数据");
    }
    /**
     * 获取物业人员详细信息
     */
    @ApiOperation(value="获取物业人员详细信息", notes="获取物业人员详细信息")
    @PreAuthorize(hasPermi = "park:wyUser:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(wyUserService.selectWyUserById(id));
    }

    /**
     * 新增物业人员
     */
    @ApiOperation(value="新增物业人员", notes="新增物业人员")
    @PreAuthorize(hasPermi = "park:wyUser:add")
    @Log(title = "物业人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyUser wyUser) {
        return toAjax(wyUserService.insertWyUser(wyUser));
    }

    /**
     * 修改物业人员
     */
    @ApiOperation(value="修改物业人员", notes="修改物业人员")
    @PreAuthorize(hasPermi = "park:wyUser:edit")
    @Log(title = "物业人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyUser wyUser) {
        return toAjax(wyUserService.updateWyUser(wyUser));
    }

    /**
     * 删除物业人员
     */
    @ApiOperation(value="删除物业人员", notes="删除物业人员")
    @ApiImplicitParam(name = "ids", value = "物业人员ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:wyUser:remove")
    @Log(title = "物业人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(wyUserService.deleteWyUserByIds(ids));
    }
}
